package action.paiement;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

import service.generationpdf.GestionGenerationPDF;
import bean.client.Client;
import bean.produit.Panier;

import action.general.NotreServlet;

public class AutrePaiementAction extends NotreServlet{
	public ActionForward execute( ActionMapping pMapping, ActionForm pForm, HttpServletRequest pRequest, HttpServletResponse pResponse)
	{
		ActionErrors errors = new ActionErrors();
        int id_commande;
        id_commande=(Integer)pRequest.getAttribute("Num_Commdande");
		HttpSession httpsession = pRequest.getSession();
		Object objClient = httpsession.getAttribute("client");
		Client client = (Client)objClient;
		

        Object objPanier = httpsession.getAttribute("panier");
		Panier panier = (Panier)objPanier;
		        
        
        try {
			GestionGenerationPDF.genereFichierPdf(Integer.toString(client.getId()), Integer.toString(id_commande), pRequest.getSession().getServletContext(), panier,panier.getMontantTotal()-panier.getTotalAPayer());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			errors.add("errors",new ActionMessage("errors.exception"));
			saveErrors(pRequest,errors); 
			return (new ActionForward(pMapping.getInput()));
		}

     
        httpsession.removeAttribute("panier");
		
		
		return pMapping.findForward("success");
	}
	
}
